package com.msb.mall.order.utils;

import com.alibaba.fastjson.JSON;
import com.msb.common.constant.OrderConstant;
import com.msb.common.dto.SeckillOrderDto;
import com.msb.mall.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 秒杀订单消息监听
 */
@Slf4j
@RocketMQMessageListener(topic = OrderConstant.ROCKET_SECKILL_ORDER_TOPIC,consumerGroup = "seckill-order-consumer")
@Component
public class SeckillOrderMsgConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderService orderService;

    @Override
    public void onMessage(String order) {
        SeckillOrderDto seckillOrderDto = JSON.parseObject(order, SeckillOrderDto.class);
        log.info("------------->>>接收到消息：seckill-order-consumer="+seckillOrderDto);
        orderService.createSeckillOrder(seckillOrderDto);
    }
}
